package com.haier.dreambox.demo;

import android.app.Application;
import com.haier.dreambox.demo.bean.uplus.Device;
import org.androidannotations.annotations.EApplication;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by smalant on 14/12/26.
 */

@EApplication
public class MyApplication extends Application {

    private List<Device> userDeviceArray = new ArrayList<Device>();

    public static String getSequenceId() {
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);
        String date = sf.format(new Date());
        int num = (int) (Math.random() * 6) + 1;
        date = date + num;
        return date;
    }


    /**
     * 缓存用户绑定的设备列表
     *
     * @param devices
     */
    public void cachHaierUserDevices(Device[] devices) {
        if (devices == null) throw new RuntimeException("用户设备列表为空！");
        this.userDeviceArray.clear();
        for (Device device : devices) {
            this.userDeviceArray.add(device);
        }
    }

    /**
     * 返回用户绑定的设备列表
     *
     * @return
     */
    public List<Device> getCachedUserDevices() {
        return userDeviceArray;
    }

    /**
     * 返回用户绑定的设备列表
     *
     * @return
     */
    public List<String> getCachedUserDeviceMacs() {
        List<String> macList = new ArrayList<String>();
        for (Device device : userDeviceArray) {
            macList.add(device.mac);
        }
        return macList;
    }


    /**
     * 是否是当前用户关联的设备
     *
     * @param deviceMac
     * @return
     */
    public boolean isUserDevice(String deviceMac) {

        if (userDeviceArray != null) {
            for (Device device : userDeviceArray)
                if (deviceMac.equals(device.mac)) {
                    return true;
                }
        }
        return false;
    }
}
